var board_item_json = '[]';
var ws = new WebSocket("ws://127.0.0.1:9090/webserver");
var connect_success = false;

ws.onopen = function (ev) {
    console.log("find server success,try to connect...");
    connect_success = true;
    ws.send("root:123456");
};

ws.onmessage = function (ev) {
    if(ev.data === "congratulation") {
        console.log("connection established");
        ws.send("MSGBOARD?GET");
    }
    else if(ev.data === "sorry") {
        console.log("connect failed");
        connect_success =false;
    }
    else if(ev.data.split("?")[0] === "MSGBOARD" && (ev.data.split("?")[1] === "SEND")) {
        let ev_data = ev.data.split("?");
        ev_data.splice(0,2);
        board_item_json = ev_data.join("?");
    }
};

ws.onerror = function (ev) {
    console.log("connect error");
    connect_success = false;
};
